from enum import IntEnum

class ComDev:
    class ServerType(IntEnum):
        CN_NORMAL = 1
        OVERSEA_NORMAL = 2
        OVERSEA_DEVELOP = 3
        BUSINESS_OVERSEA_NORMAL = 4
        BUSINESS_DEVELOP = 5
        LOCAL_DEMO = 6
    
    class ServiceParams:
        def __init__(self, serviceId = "", para = "", paraValue = 0):
            self.serviceId = serviceId
            self.para = para
            self.paraValue = paraValue
    
    class DeviceWeak(IntEnum):
        WEAK_BIT_MON = 0x40
        WEAK_BIT_TUE = 0x20
        WEAK_BIT_WED = 0x10
        WEAK_BIT_THU = 0x8
        WEAK_BIT_FRI = 0x4
        WEAK_BIT_SAT = 0x2
        WEAK_BIT_SUN = 0x1

    class Timer:
        def __init__(self, id = "", enable = False, start = "", end = "0", services = [], week = 0):
            self.id = id
            self.enable = enable
            self.start = start
            self.end = end
            self.services = services
            self.week = week

        def Reset(self):
            self.id = ""
            self.enable = False

            self.start = ""
            self.end = ""

            self.services.clear()

            self.week = 0

        def GetServiceString(self):
            return "delay GetServiceString not complete"
            # serviceString = ""
            # for srvId in range(len(self.services)):
            #     if self.services[srvId].serviceId == "switch1":
            #         serviceString += "开关1 "
            #     elif self.services[srvId].serviceId == "switch2":
            #         serviceString += "开关2 "
            #     elif self.services[srvId].serviceId == "switch3":
            #         serviceString += "开关3 "
            #     else: #self.services[srvId].serviceId == "switch4"
            #         serviceString += "开关4 "
            #     serviceString += ("打开;  " if self.services[srvId].paraValue else "关闭;  ")

            #     print("Service{}, srvId={}, para={}, paraValue={}.".format(srvId, \
            #         self.services[srvId].serviceId, \
            #         self.services[srvId].para, \
            #         self.services[srvId].paraValue))
            # return serviceString[:-3]

        def GetWeekString(self):
            weekString = ""
            if (self.week & int(ComDev.DeviceWeak.WEAK_BIT_MON)) != 0:
                weekString = "周一,"
            if (self.week & int(ComDev.DeviceWeak.WEAK_BIT_TUE)) != 0:
                weekString += "周二,"
            if (self.week & int(ComDev.DeviceWeak.WEAK_BIT_WED)) != 0:
                weekString += "周三,"
            if (self.week & int(ComDev.DeviceWeak.WEAK_BIT_THU)) != 0:
                weekString += "周四,"
            if (self.week & int(ComDev.DeviceWeak.WEAK_BIT_FRI)) != 0:
                weekString += "周五,"
            if (self.week & int(ComDev.DeviceWeak.WEAK_BIT_SAT)) != 0:
                weekString += "周六,"
            if (self.week & int(ComDev.DeviceWeak.WEAK_BIT_SUN)) != 0:
                weekString += "周日,"
            if (self.week == 128):
                weekString += "只执行一次,"
            return weekString[:-1]

    class Delay:
        def __init__(self, delayId = "1", enable = False, start = 0, end = "", services = []):
            self.id = delayId
            self.enable = enable
            self.start = start
            self.end = end
            self.services = services

        def Reset(self):
            self.id = "1"
            self.enable = False
            self.start = 0
            self.end = 0
            self.services.clear()

        def GetServiceString(self):
            return "timer GetServiceString not complete"
            # serviceString = ""
            # for srvId in range(len(self.services)):
            #     if self.services[srvId].serviceId == "switch1":
            #         serviceString += "开关1 "
            #     elif self.services[srvId].serviceId == "switch2":
            #         serviceString += "开关2 "
            #     elif self.services[srvId].serviceId == "switch3":
            #         serviceString += "开关3 "
            #     else: #self.services[srvId].serviceId == "switch4"
            #         serviceString += "开关4 "
            #     serviceString += ("打开;  " if self.services[srvId].paraValue else "关闭;  ")

            #     print("Service{}, srvId={}, para={}, paraValue={}.".format(srvId, \
            #         self.services[srvId].serviceId, \
            #         self.services[srvId].para, \
            #         self.services[srvId].paraValue))
            # return serviceString[:-3]

    class FullStatus:
        def __init__(self):
            # 基本信息，通过heartbeat接收
            self.mac = ""
            self.firmwareVersion = ""
            self.hardwareVersion = ""

            self.protocol = ""
            self.modelId = ""
            self.heartbeatFreq = 0

            self.wifiSsid = ""
            self.wifiRssi = ""
            self.wifiBssid = ""

            # 调试信息，通过getFullStatus接收
            self.serverType = 0
            self.bindStatus = 0
            self.mqttStatus = 0

            self.chipType = ""
            self.serialNum = ""
            self.buildTime = ""

            self.timezone = ""
            self.nowTimestamp = 0

    class OtaProcess:
        def __init__(self):
            self.process = ""
            self.startTime = ""
            self.totalTime = ""
            self.progress = ""
            self.frequency = ""
            
    class OtaResult:
        def __init__(self):
            self.result = 0
            self.failReason = ""
